﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BBMS.DLL.Base;
using BBMS.DLL.DataContract;

namespace BBMS.DLL.Forms
{
    public partial class frmImportDiscount : Form
    {
        ArrayList arNcc = new ArrayList();
        NhaCungCap curNcc = null;
        public frmImportDiscount(NhaCungCap ncc)
        {
            InitializeComponent();
            curNcc = ncc;
        }

        private void frmImportDiscount_Load(object sender, EventArgs e)
        {
            txtMaNCC.Text = curNcc.Ma;
            txtMST.Text = curNcc.MSTVAT;
            txtTenNCC.Text = curNcc.Ten;
            cbxLoaiCTThu.SelectedIndex = 0;
        }

        private void dtDenNgay_ValueChanged(object sender, EventArgs e)
        {
            if (dtDenNgay.Value.Date < dtTuNgay.Value.Date)
                dtDenNgay.Value = dtTuNgay.Value.Date;
        }

        private void dtTuNgay_ValueChanged(object sender, EventArgs e)
        {
            if (dtDenNgay.Value.Date < dtTuNgay.Value.Date)
                dtDenNgay.Value = dtTuNgay.Value.Date;
        }

        private void btnLoc_Click(object sender, EventArgs e)
        {
            if(cbxLoaiCTThu.SelectedIndex < 0){
                MessageBox.Show("Hãy chọn loại chứng từ thu");
                return;
            }

            lvList.Items.Clear();
            /*ChungTuThu ctThu = new ChungTuThu();
            FilterParams fParams = new FilterParams();
            fParams.ArParams.Add(new FilterCondition("NgayCT","TuNgay",dtTuNgay.Value.Date,SQLOperator.GREATER_OR_EQUAL));
            fParams.ArParams.Add(new FilterCondition("NgayCT","DenNgay",dtDenNgay.Value.Date,SQLOperator.LOWER_OR_EQUAL));
            if (cbxLoaiCTThu.SelectedIndex == 0) ctThu.SetExWhereClause(" (LoaiCT = 'CTCK' OR LoaiCT = 'CKTM') ");
            else if(cbxLoaiCTThu.SelectedIndex == 1) ctThu.SetExWhereClause(" (LoaiCT = 'CTCK') ");
            else if (cbxLoaiCTThu.SelectedIndex == 2) ctThu.SetExWhereClause(" (LoaiCT = 'CKTM') ");
            ArrayList ar = ctThu.GetAllObject(fParams);
            if (ar == null || ar.Count == 0)
            {
                MessageBox.Show("Không tìm thấy bản ghi tương ứng");
            }
            else
            {
                foreach (ChungTuThu obj in ar)
                {
                    ListViewItem it = new ListViewItem(obj.MaCT);
                    it.SubItems.Add(obj.SoCT);
                    it.SubItems.Add(ObjectLists.LoaiChungTuList.getObjectName(obj.LoaiCT));
                    it.SubItems.Add(obj.NgayCT.ToString("dd/MM/yyyy"));
                    it.SubItems.Add(CommonTools.Helper.MoneyString(obj.GiaTriCT));
                    it.SubItems.Add(CommonTools.Helper.MoneyString(obj.GiaTriDaTT));
                    it.Tag = obj;
                    lvList.Items.Add(it);
                }
            }*/
        }
        //public ChungTuThu RetChungTuThu = null;
        public ArrayList PhieuThuList
        {
            get{
                return arNcc;
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (lvList.CheckedItems.Count > 0)
            {
                MessageBox.Show("Hãy chọn phiếu thu.");
                return;
            }
            arNcc.Clear();
            foreach (ListViewItem it in lvList.CheckedItems)
                arNcc.Add(it.Tag);
            this.DialogResult = DialogResult.OK;
        }

        private void btnNew_Click(object sender, EventArgs e)
        {

        }
    }
}
